package edu.sctu.zcy.month201506.day20150626.fastjson;

import com.alibaba.fastjson.JSON;
import edu.sctu.zcy.month201506.day20150623.jsontest.JsonAppBean1;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * Created by user24 on 2015/6/26.
 */
public class FastJson {


    public static String json;

    public static String getPageMessage(String url){


        HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
        CloseableHttpClient closeableHttpClient = httpClientBuilder.build();

        HttpGet httpGet = new HttpGet(url);

        try {
            HttpResponse httpResponse = closeableHttpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
            json = EntityUtils.toString(httpEntity);

        } catch (IOException e) {
            e.printStackTrace();
        }

        return json;
    }

    public JsonAppBean1 getData(String json){

        JsonAppBean1 jsonAppBean1 = JSON.parseObject(json,JsonAppBean1.class);

        return jsonAppBean1;
    }
}
